; startup.s
; 蒋晓岗<kerndev@foxmail.com>

; <h> Stack Configuration
;   <o>  Stack Size (in Bytes) <0x0-0xFFFFFFFF:8>
; </h>
Stack_Size      EQU     0x000001000

                AREA    STACK, NOINIT, READWRITE, ALIGN=3
Stack_Mem       SPACE   Stack_Size
__initial_sp


; <h> Heap Configuration
;   <o>  Heap Size (in Bytes) <0x0-0xFFFFFFFF:8>
; </h>

Heap_Size       EQU     0x00000000

                AREA    HEAP, NOINIT, READWRITE, ALIGN=3
__heap_base
Heap_Mem        SPACE   Heap_Size
__heap_limit

;*******************************************************************************
; Address 0 at Reset
;*******************************************************************************
	AREA    RESET, CODE, READONLY
	B		Reset_Handler
	NOP
	
;*******************************************************************************
; Reset_Handler
;*******************************************************************************
	AREA    |.text|, CODE, READONLY
	PRESERVE8
	
Reset_Handler    PROC
	EXPORT  Reset_Handler [WEAK]
	IMPORT  __main
	
	MSR     CPSR_c, #0xD3     ;SVC mode
	LDR     SP, =__initial_sp
	BL      __main

	ENDP
	ALIGN
	
;*******************************************************************************
; User Stack and Heap initialization
;*******************************************************************************
	AREA    |.text|, CODE, READONLY
	
	EXPORT  __user_initial_stackheap
__user_initial_stackheap
	LDR     R0, = Heap_Mem
	LDR     R1, =(Stack_Mem + Stack_Size)
	LDR     R2, = Heap_Mem + Heap_Size
	LDR     R3, = Stack_Mem
	BX      LR
	ALIGN

	END
